package com.view.jameson.androidrecyclerviewcard;

import android.content.Context;
//import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

//import com.bumptech.glide.Glide;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.view.jameson.library.BannerAdapterHelper;

import java.util.ArrayList;
import java.util.List;

//import jameson.io.library.util.ToastUtils;

/**
 * Created by jameson on 8/30/16.
 * changed by 二精-霁雪清虹 on 2017/11/19
 */
class CardAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private static final int VIEW_TYPE_HEADER = 0;
    private static final int VIEW_TYPE_ITEM = 1;
    private static final int VIEW_TYPE_FOOTER = 2;

    private View headerView;
    private View footerView;
    private List<CardViewBean> mList = new ArrayList<>();
    private BannerAdapterHelper mBannerAdapterHelper = new BannerAdapterHelper();
    private Context mContext;

    public CardAdapter(List<CardViewBean> mList, Context mContext) {
        this.mList = mList;
        this.mContext = mContext;
    }

    public List<CardViewBean> getList() {
        return mList;
    }

    public void setList(List<CardViewBean> list) {
        mList = list;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//        if (viewType == VIEW_TYPE_HEADER) {
//            headerView = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_empty_item, parent, false);
//            mBannerAdapterHelper.onCreateViewHolder(parent, headerView);
//            return new HeaderViewHolder(headerView);
//        } else if (viewType == VIEW_TYPE_FOOTER) {
//            footerView = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_empty_item, parent, false);
//            mBannerAdapterHelper.onCreateViewHolder(parent, footerView);
//            return new FooterViewHolder(footerView);
//        } else {
            View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_card_item, parent, false);
//            mBannerAdapterHelper.onCreateViewHolder(parent, itemView);
            return new ContentViewHolder(itemView);
//        }

    }

    @Override
    public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
//        mBannerAdapterHelper.onBindViewHolder(holder.itemView, position, getItemCount());
//        if (getItemViewType(position) == VIEW_TYPE_ITEM) {
            ImageView mImageView = ((ContentViewHolder) holder).mImageView;
            String pic = mList.get(position % mList.size()).getPicturePath2();
            Log.e("图片地址111", pic + "==");
            Glide.with(mContext)
                    .load(pic)
//                    .placeholder(R.mipmap.ic_launcher)
                    .into(mImageView);
//            ((ContentViewHolder) holder).mImageView.setImageResource(mList.get(position % mList.size()).getPicturePath());
            ((ContentViewHolder) holder).mImageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
//                    ToastUtils.show(((ContentViewHolder) holder).mImageView.getContext(), "" + position);
                    ((RecyclerView) holder.itemView.getParent()).smoothScrollToPosition(position);
                }
            });
//        } else {
//
//        }

    }


//    public void setHeaderView(View headerView) {
//        this.headerView = headerView;
//    }
//
//    public void setFooterView(View footerView) {
//        this.footerView = footerView;
//    }


    @Override
    public int getItemViewType(int position) {
//        if (position == 0 && mList.size() <= 3) {
//            return VIEW_TYPE_HEADER;
//        }
//        if (position == getItemCount() - 1 && mList.size() <= 3) {
//            return VIEW_TYPE_FOOTER;
//        }
        return VIEW_TYPE_ITEM;
    }

    @Override
    public int getItemCount() {
        return mList.size();
//        if (mList != null && mList.size() <= 3) {
////            return mList.size() + 2;
//            return mList.size();
//        } else {
//            return Integer.MAX_VALUE;
//        }

    }


    public class ContentViewHolder extends RecyclerView.ViewHolder {
        public final ImageView mImageView;

        public ContentViewHolder(final View itemView) {
            super(itemView);
            mImageView = (ImageView) itemView.findViewById(R.id.imageView);
        }

    }

    public class HeaderViewHolder extends RecyclerView.ViewHolder {
        public HeaderViewHolder(View itemView) {
            super(itemView);
        }
    }

    public class FooterViewHolder extends RecyclerView.ViewHolder {
        public FooterViewHolder(View itemView) {
            super(itemView);
        }
    }

}
